package com.clstu.map;

import java.util.Hashtable;
import java.util.Objects;

public class HashTableExercise {
    public static void main(String[] args) {
        Hashtable table=new Hashtable();//机制与hashMap类型，区别是table表是entry[] 类型的，而
                                      //   HashMap 的table是Node[] 类型的
        table.put("john",100);
        //table.put(null,100);
        //table.put("john",null);都有异常，k-v都不允许为null
        table.put("lucy",100);
        table.put("lily",100);
        table.put("lily",99);
        for (int i = 0; i < 50; i++) {
            table.put(new B(i),i);//扩容机制，变化规律11，8-》23，17-》47，35-》....-》2*n+1，(2*n+1)*0.75
        }
    }
}
class B{
    public int n;
    public static int h=0;
    public B(int n) {
        this.n = n;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        B b = (B) o;
        return n == b.n;
    }

    @Override
    public int hashCode() {
        return ++h;
    }
}